package acwing.算法题;/**
 * @author： li
 * @date： 2022-04-05 14:47
 * @version 1.0
 */
import java.io.*;
import java.util.*;
public class 亲戚_并查集1 {
    static int[] fa = new int[20005];
    //路径压缩
    static int find1(int x){
        if(fa[x]!=x)
            fa[x]=find1(fa[x]);
        return fa[x];
    }
    static void join1(int x,int y){
        int fx =find1(x);int fy=find1(y);
        if(fx!=fy)
            fa[fx]=fy;
    }
    static boolean isCon(int x,int y){
        return find1(x)==find1(y);
    }
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    public static void main(String[] args) throws IOException {
        in.nextToken();
        int n=(int)in.nval;//人数
        in.nextToken();
        int m =(int)in.nval;//关系数据
        for(int i=1;i<=n;i++){
            fa[i]=i;
        }
        for(int i=1;i<=m;i++) {
            in.nextToken();
            int x = (int) in.nval;
            in.nextToken();
            int y = (int) in.nval;
            join1(x, y);
        }
        in.nextToken();
        int q =(int)in.nval;
        for(int i=1;i<=q;i++){
            in.nextToken();
            int j =(int)in.nval;
            in.nextToken();
            int k =(int)in.nval;
            if(isCon(j,k))
                out.write("Yes\n");
            else
                out.write("No\n");
        }
        out.flush();
    }
}
